package com.imcoke.abchat.web.service;

import com.imcoke.abchat.common.UserDetailsFactory;
import com.imcoke.abchat.domain.User;
import com.imcoke.abchat.web.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

/**
 * @Author ccoke
 * @Description 连接Dao层，获取用户
 * @Date: 17:05 2017-11-28
 */
@Service
public class UserDetailsServiceImpl implements UserDetailsService {
    @Autowired
    private UserMapper mUserMapper;
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        User user = mUserMapper.selectUserByUserName(username);
        if (user == null){
            throw new UsernameNotFoundException("未找到该用户");
        }
        return UserDetailsFactory.create(user);
    }
}
